﻿Public Class clsGt

    Public Function getGtList(startTime As String, endTime As String) As DataTable
        Dim szSql As String = ""
        szSql &= " select a.*,concat_ws('',b.size,c.size) as size from sf.b_gt a "
        szSql &= "left join sf.t_mst_gjb b on a.material_code = b.material_code and a.oper_type = '0' "
        szSql &= "left join sf.t_mst_flb c on a.material_code = c.material_code and a.oper_type = '1' "
        szSql &= "where 1=1 "
        If startTime <> "" Then
            szSql &= " and a.update_time >= '" + startTime + "'"
        End If
        If endTime <> "" Then
            szSql &= " and a.update_time <= '" + endTime + "'"
        End If
        szSql &= " and ((a.oper_type = '1' and a.status = '2') or (a.oper_type = '0' and (a.status = '3' or a.status = '2'))) "
        Return DBacs.ExecuteSql(szSql, -1)
    End Function


    Public Function getGt(oper_type As String, status As String) As DataTable
        Dim szSql As String = ""
        szSql &= "select a.*,b.size from sf.b_gt a "
        If oper_type.Equals("0") Then
            szSql &= "left join sf.t_mst_gjb b on a.material_code = b.material_code "
        End If
        If oper_type.Equals("1") Then
            szSql &= "left join sf.t_mst_flb b on a.material_code = b.material_code "
        End If
        szSql &= " where a.validity = ? and a.oper_type= ? and a.status in (" & status & ") "
        Return DBacs.ExecuteSql(szSql, -1, "1", oper_type)
    End Function

    Public Function getCurrentGt(oper_type As String, status As String, procedure_no As String) As DataTable
        Dim szSql As String = ""
        szSql &= "select a.sys_id,a.oper_type,a.type_value,a.material_code,a.batch_no,a.picking_num,a.status,a.operator,a.update_time,a.assist_marker,a.assist_marker_jnj,b.ok_num,b.ng_num,b.procedure_no,c.size "
        szSql &= " from sf.b_gt a left join sf.b_gt_result_details b on a.sys_id = b.b_gt_sys_id "
        If oper_type.Equals("0") Then
            szSql &= "left join sf.t_mst_gjb c on a.material_code = c.material_code "
        End If
        If oper_type.Equals("1") Then
            szSql &= "left join sf.t_mst_flb c on a.material_code = c.material_code "
        End If
        szSql &= " where a.validity = ? and a.oper_type = ? and a.status = ? and b.procedure_no = ?"
        Return DBacs.ExecuteSql(szSql, -1, "1", oper_type, status, procedure_no)
    End Function

    Public Function update_assist_marker(sys_id As String, assist_marker As String) As Integer
        Dim sql As String = "UPDATE sf.b_gt SET assist_marker_jnj = ?, update_time= (SELECT CURRENT_TIMESTAMP(6)) WHERE sys_id = ? "
        Dim rtn As Integer = DBacs.ExecuteUpdateSql(sql, -1, assist_marker, sys_id)
        Return rtn
    End Function

    Public Function update_validity(sys_id As String) As Integer
        Dim sql As String = "UPDATE sf.b_gt SET sys_id = ?, update_time= (SELECT CURRENT_TIMESTAMP(6)) WHERE sys_id = ? "
        Dim rtn As Integer = DBacs.ExecuteUpdateSql(sql, -1, "0", sys_id)
        Return rtn
    End Function

    Public Function save(status As String, sys_id As String) As Integer
        Dim sql As String = ""
        Dim rtn As Integer
        sql &= "UPDATE sf.b_gt SET status = ?, update_time = (SELECT CURRENT_TIMESTAMP(6)) WHERE sys_id = ? "
        rtn = DBacs.ExecuteUpdateSql(sql, -1, status, sys_id)
        Return rtn
    End Function
End Class
